<?php
/**
 * The MIT License
 *
 * Copyright (c) <year> <copyright holders>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author Damiano Ciarla
 * @package plugin
 * @subpackage log/class/conf
 */
class Log_Config
{
	/**
	 * Connessione con libreria "db"
	 */
	const BXD_DB_LIB = 1;

	/**
	 * Connessione con "mysql_connect"
	 */
	const CONN_MYSQL = 2;

	/**
	 * Imposta la scrittura tramite la libreria "db"
	 *
	 * @var bool
	 */
	private $_useBxdDatabase = false;

	/**
	 * Imposta la scrittura dei log con una connessione "mysql_connect"
	 *
	 * @var bool
	 */
	private $_useConnMysql = false;

	/**
	 * Host per la connessione al database
	 *
	 * @var string
	 */
	private $_customDbConf_host;

	/**
	 * Username per accedere al database
	 *
	 * @var string
	 */
	private $_customDbConf_username;

	/**
	 * Password per accedere al database
	 *
	 * @var string
	 */
	private $_customDbConf_password;

	/**
	 * Nome del database su cui operare
	 *
	 * @var string
	 */
	private $_customDbConf_dbname;

	/**
	 * Prefisso delle tabelle che servono al plugin per scrivere i log su database
	 *
	 * @var string
	 */
	public $prefixTable = "plugin_log_";

	/**
	 * Imposta se tracciare gli errori generati dal php. Con la variabile "$errorTypes"
	 * si può scegliere il livello di tracciamento
	 *
	 * @var bool
	 */
	public $logError = true;

	/**
	 * Tipologia di errori che devono essere notificati nel database.
	 * I valori possibili sono gli stessi della funzione "error_reporting".
	 * Se non si specifica alcun valore saranno notificati tutti gli errori indipendentemente
	 * delle impostazioni inserite nella funzione "error_reporting"
	 *
	 * @var int
	 */
	public $errorTypes;

	/**
	 * Imposta se tracciare le eccezioni lanciate dal php
	 *
	 * @var bool
	 */
	public $logException = true;

	public function useConnectionMysql($host, $username, $password, $dbname)
	{
		$this->_useBxdDatabase = false;
		$this->_useConnMysql = true;

		$this->_customDbConf_host = $host;
		$this->_customDbConf_username = $username;
		$this->_customDbConf_password = $password;
		$this->_customDbConf_dbname = $dbname;
	}

	public function useBxdLibDb($host = null, $username = null, $password = null, $dbname = null)
	{
		$this->_useConnMysql = false;
		$this->_useBxdDatabase = true;

		$this->_customDbConf_host = $host;
		$this->_customDbConf_username = $username;
		$this->_customDbConf_password = $password;
		$this->_customDbConf_dbname = $dbname;
	}

	public function _getConnection()
	{
		$connType = 0;

		if($this->_useBxdDatabase)
			$connType = self::BXD_DB_LIB;

		if($this->_useConnMysql)
			$connType = self::CONN_MYSQL;

		return array($connType, $this->_customDbConf_host, $this->_customDbConf_username, $this->_customDbConf_password, $this->_customDbConf_dbname);
	}
}
?>
